package zero.tech.games.gate.topic;

import java.util.List;

import com.alibaba.fastjson.JSONObject;

import zero.tech.games.common.TopicOrder;
import zero.tech.games.gate.hot.NotifyUtil.NotifyData;
import zero.tech.redis.topic.TopicChannelType;
import zero.tech.redis.topic.TopicProcess;
import zero.tech.wsnet.controller.CacheOnline;
import zero.tech.wsnet.controller.Controller;

public class NotifyDataTopic extends TopicProcess{

	@Override
	public String orderType() {
		return TopicOrder.NOTIFY_DATA;
	}

	@Override
	public void process(String message) throws Exception {
		NotifyData notifyData = JSONObject.parseObject(message, NotifyData.class);
		List<Integer> uids=notifyData.getUids();
		for(Integer uid:uids) {
			Controller controller= CacheOnline.getCache().getOnlines().get(uid);
			if(controller!=null&&controller.getWebClient()!=null&&controller.getWebClient().isAlive()) {
				controller.getWebClient().sendMessage(notifyData.getMsg());
			}
		}
	}

	@Override
	public TopicChannelType channelType() {
		return TopicChannelType.NOTIFY_DATA;
	}

}
